﻿#**************************************************************************
#*********************---------------------------------**********************
#********************|    Copyright (c) 2003 - 2022    |*********************
#********************|      by VIRE Technologies.        |*********************
#********************|       All Rights Reserved           |*********************
#*********************---------------------------------**********************
#**************************************************************************
#
# If any question, please write to VIRE Technologies for
# more information:
#			Techart Plaza, A16, No.30 XueYuan Road,
#			Haidian District Beijing 100083,
#			P.R. China
#
# For more, please visit company website: www.vire.cn
#**************************************************************************
message(STATUS "CMAKE_VERSION: " ${CMAKE_VERSION})

cmake_minimum_required(VERSION 3.3...3.27)

#============================================================
#============================================================
project(EWX_Plugin_Test)

#============================================================
#============================================================
#============================================================
#########################################################
#注意：
#   使用此工程用例代码需使用我方提供的cmake版本进行预处理，否则会报错
#########################################################
#============================================================
#添加系统查找模块环境
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules)


#============================================================

#初始化环境
#1.1 包含公共cmake模块
#此宏必须需要
IF(NOT EXISTS ${PROJECT_SOURCE_DIR}/CMakeModules/_MustInclude.cmake)
   message(FATAL_ERROR "No Find _MustInclude.cmake...Process Nothing...")
ENDIF()
include(_MustInclude)
MUST_INCLUDE(ONLY_USE_MODULES)

#1.2 包含三方库适配器模块
SET(_LOCAL_PKG_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules)
set(CMAKE_MODULE_PATH ${_LOCAL_PKG_MODULE_PATH} ${CMAKE_MODULE_PATH})
include(EWX_3RD_Support)


#============================================================
#============================================================
#============================================================
#conan support.
#这里设置编绎的三方库的模式
set(USE_CONAN_MODE "NULL" CACHE STRING 
   "Is Use Conan Mode Selection...")
set_property(CACHE USE_CONAN_MODE PROPERTY STRINGS "NULL" 
   "YES"
   "NO"
)

set(use_conan_mode OFF)
IF(${USE_CONAN_MODE} STREQUAL "YES")
   MACRO_CHECK_HAS_CONAN_ENV(has_conan)
   IF(has_conan)
      #conan环境准备
      # 指定用户脚本模板
      if(WIN32)
         set(CONAN_BAT_SHELL_TEMPLATE ${PROJECT_SOURCE_DIR}/CMakeModules/Templates/pro_conan_install.bat.in)
      else()
         set(CONAN_BAT_SHELL_TEMPLATE ${PROJECT_SOURCE_DIR}/CMakeModules/Templates/pro_conan_install.sh.in)
      endif()
      # ==============
      CONAN_SUPPORT(conan_run_time_path)
      # ==============
      message(NOTICE "conan_run_time_path=${conan_run_time_path}")

      #这里全局变量的赋值处理,用于后期的模块判断处理
      SET(EWX_HAS_CONAN_ENV ${${PROJECT_NAME}_HAS_CONAN_ENV})
      SET(use_conan_mode ${EWX_HAS_CONAN_ENV})

      # 此变量可以控制cmake_gui的打印开关
      OPTION(EWX_CONAN_DEBUG_OUTPUT "" OFF)
      IF(EWX_CONAN_DEBUG_OUTPUT)
         SET(CONAN_CMAKE_SILENT_OUTPUT OFF)
      ELSE()
         SET(CONAN_CMAKE_SILENT_OUTPUT TRUE)
      ENDIF()
   endif()
ELSEIF(${USE_CONAN_MODE} STREQUAL "NO")
   message(NOTICE "=======EWX Use Local 3RD Party Mode ....")
ELSE()
   message(FATAL_ERROR "Must Select Type USE_CONAN_MODE = ${USE_CONAN_MODE}")
ENDIF()

# 公共三方库包名和版本定义
include(3RDPartyVar)

if(NOT use_conan_mode)
   #==================================
   #使用本地支持conan的适配三方库包的cmake目录
   SET(SUPPORT_3RD_ROOT_DIR ${_LOCAL_PKG_MODULE_PATH}/EWX_3RD_Support)
   SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${SUPPORT_3RD_ROOT_DIR})
   include(${SUPPORT_3RD_ROOT_DIR}/Normal3RDModulesAdapter/EWX_3RD_PKGS.cmake)

   message(NOTICE "No Conan Support And Select 3RD Party Root Path...")
   #新增无conan环境编绎EWX源码的环境适配处理
   MACRO_USE_WITH_3RD_PARTY_TYPE()

   #适配标识变量为真【用的是conan的脚本适配处理】
   #本地库使用是CONAN下载的模块脚本生成，所以加入以下变量进行适配
   #本地库也使用CONAN的兼容处理
   #SET(EWX_HAS_CONAN_ENV TRUE)

   #测试处理
   #TEST_FIND_EWX_3RD_PKGS()
   #return()
endif()

#============================================================
#============================================================
#默认设置至当前工程的根目录
set(PROJECT_OUTPUT_DIR ${PROJECT_BINARY_DIR} CACHE PATH "")
#============================================================
#1.4.1 解决方案通用属性设置
set(CMAKE_CONFIGURATION_TYPES Release;RelWithDebInfo)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_OUTPUT_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_OUTPUT_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${PROJECT_OUTPUT_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_OUTPUT_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_OUTPUT_DIR}/lib)
#===========================
#1.4.2 通用系统变量的设置
SET(EWX_EXT_DIR ${CMAKE_CURRENT_LIST_DIR} CACHE STRING "" FORCE)
SET(EWX_EXT_BINARY_DIR ${PROJECT_BINARY_DIR} CACHE STRING "" FORCE)
SET(EWX_EXT_DATA_DIR ${PROJECT_SOURCE_DIR}/data CACHE STRING "" FORCE)

#增加模式生成到SDK目录
#若为FALSE，则会生成到本地的二进制目录
#两种模式生成的脚本会以此变量进行控制
OPTION(EWX_EXT_OUTPUT_TO_SDK_DIR "Build The Binary To SDK Dir" ON)

# 这里指定插件安装的根目录[定义的宏会处理具体安装到哪个子插件目录]
# 预定义子工程可能要使用的变量
SET(PLUGIN_INSTALL_DIR ${EWX_SDK_DIR}/bin)
SET(INSTALL_EXE_PATH ${EWX_SDK_DIR}/bin)
set(BUILD_SHARED_LIBS TRUE)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

#============================================================
#1.5 设置项目通用预处理宏
#==============================
#1.5.1 设置data目录宏，可以在程序中直接使用的宏
ADD_DEFINITIONS(
   -DPROJECT_DATA_DIR="${PROJECT_SOURCE_DIR}/data" 
)
#==============================
#
ADD_DEFINITIONS(-DPROMOTE_HARDWARE_EXCEPTIONS)
#==============================
if (MSVC)
   #编绎报的代码codepage问题
   add_definitions(-wd4828)
   add_definitions(-wd4819)
   add_definitions(-wd4244)
endif()

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
#SET(CMAKE_CXX_EXTENSIONS OFF)
############################################################
#add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
#add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
############################################################
if(WIN32)
   # On windows, the dll's must reside in the same path as the .exe
   if("${INSTALL_DLL_PATH}" STREQUAL "")
      set(INSTALL_DLL_PATH .)
   endif("${INSTALL_DLL_PATH}" STREQUAL "")
else(WIN32)
   # On linux, we can use rpath to locate so's in a subdirectory
   if("${INSTALL_DLL_PATH}" STREQUAL "")
      set(INSTALL_DLL_PATH ./lib)
   endif("${INSTALL_DLL_PATH}" STREQUAL "")
endif(WIN32)

############################################################
##########################三方库处理#########################
# 全部三方库使用适配模块进行处理
# 方便后期自定义安装脚本与conan环境的切换
############################################################
SET(3RD_PARTIES "")
if(WIN32)
   SET(3RD_PARTIES ${3RD_PARTIES} "qt-5.12.9")
else()
   SET(3RD_PARTIES ${3RD_PARTIES} "qt-5.15.14")
   SET(3RD_PARTIES ${3RD_PARTIES} "gtest-1.8.1")
endif()

ewx_3rd_support_pkgs(${CMAKE_CURRENT_LIST_DIR} ${3RD_PARTIES})
############################################################
############################################################
############################################################

#扩展用例目录
add_subdirectory(example_project)
############################################################
